<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>创建对象的练习</title>
	</head>
	<body>
		<script>
			//创建一个人            ① 构造函数
			var people = new Object();//创建一个对象
			people.name = "哔哔";
			people.sex = "女孩子";
			people.color = "粉色";
			people.show = function(){
				alert("我是"+this.name+"是个"+ this.sex+"喜欢"+this.color);
			}
			people.show();
			
			
			//②  字面量
			var ren = {
				name:"哩哩",
				sex:"男孩子",
				color:"蓝色",
				show:function(){
					alert("我是"+this.name+"是个"+ this.sex+"喜欢"+this.color);
				}
			}
			ren.show();
			
//		封装函数
			function everyOne(mz,xb,ys){
				var ren1 = {
					name:mz,
				    sex:xb,
				    color:ys,
				    show:function(){
					alert("我是"+this.name+"是个"+ this.sex+"喜欢"+this.color);
				    }
				}
				return ren1;
			}
//		调用函数
	        var ren2 = everyOne("娜娜","女孩子","紫色");
			ren2.show();
			var ren3 = everyOne("丫丫","女孩子","红色");
			ren3.show();
			
			
			//工厂 模式
//			需求：如果是男孩子要擅长打篮球,女孩子要会唱歌
			//封装函数
			function everyOne1(mz,xb,ys,lanqiu,changge){
				var child = {
					name:mz,
				    sex:xb,
				    color:ys,
				    te:lanqiu,
				    chang:changge,
				    show1:function(){
				    	if(this.sex == "男孩子"){
				    		alert("我是" + this.name + "是个" + this.sex + "喜欢" + this.color + "擅长" + this.te);
				    	}else{
				    		this.te ="";
				    		this.chang=lanqiu;
					        alert("我是" + this.name + "是个" + this.sex + "喜欢" + this.color + "爱好" + this.chang);
					     }
				    }
				}
				return child;
			}
//		调用函数
	        var child1 = everyOne1("娜娜","女孩子","紫色","唱歌");
			child1.show1();
			var child2 = everyOne1("丫丫","男孩子","黑色","篮球");
			child2.show1();
			
		</script>
	</body>
</html>
